#include "TerminatorRecord.h"

#include <QDebug>

TerminatorRecord::TerminatorRecord()
{

}

QString TerminatorRecord::endCodeType(TerminatorRecord::EndCode code)
{
    return endCodeList.at(code);
}

QString TerminatorRecord::buildRecord() const
{
    QString record = recordTypeSymbol(RecordType::Terminator);

    record += FIELD;
    record += QString::number(frameIndex);
    record += FIELD;
    record += endCodeList.value(endCode);
    record += CR;

    return record;
}

bool TerminatorRecord::analyzeRecord(const QString &str)
{
    QStringList fields = str.split(FIELD);

    if(fields.count() < 3 || fields.value(0) != recordTypeSymbol(RecordType::Terminator)) {
        // qWarning() << "ResultRecord: Syntax Error!";
        return false;
    }

    if(endCodeList.indexOf(fields[2]) >= 0)
        endCode = static_cast<EndCode>(endCodeList.indexOf(fields[2]));

    return true;
}
